package com.fulihui.wgj.auth.controller;

import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * Created by LeeSon on 2016/11/16 0016.
 */
@ControllerAdvice
@Controller
public class ExceptionHandler implements ErrorController {
    private static final String ERROR_PATH = "/error";

    @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class)
    public ModelAndView errorHandler_500(HttpServletRequest req, Exception e) throws Exception {
        ModelAndView mav = new ModelAndView();
        mav.addObject("errorUrl", req.getRequestURL());
        mav.addObject("errorMsg", e);
        mav.setViewName("500");
        return mav;
    }

    @RequestMapping(ERROR_PATH)
    public String handleError() {
        return "404";
    }

    @Override
    public String getErrorPath() {
        return ERROR_PATH;
    }
}